package com.sgcc.nfc.lock.data.remote.api

import com.sgcc.nfc.lock.core.network.ApiResponse
import com.sgcc.nfc.lock.data.remote.dto.PagedDataDto
import com.sgcc.nfc.lock.data.remote.dto.auth.UserDto
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

interface UserApi {

    @GET("/api/v1/user/list")
    suspend fun getUsers(
        @Query("pageNum") pageNum: Int,
        @Query("pageSize") pageSize: Int,
        @Query("roleType") roleType: Int? = null,
        @Query("regionId") regionId: Long? = null,
        @Query("keyword") keyword: String? = null
    ): ApiResponse<PagedDataDto<UserDto>>

    @POST("/api/v1/user/add")
    suspend fun createUser(@Body request: CreateUserRequest): ApiResponse<Unit>

    @PUT("/api/v1/user/edit/{userId}")
    suspend fun updateUser(
        @Path("userId") userId: Long,
        @Body request: UpdateUserRequest
    ): ApiResponse<Unit>

    @DELETE("/api/v1/user/delete/{userId}")
    suspend fun deleteUser(@Path("userId") userId: Long): ApiResponse<Unit>

    @PUT("/api/v1/user/resetPassword/{userId}")
    suspend fun resetPassword(
        @Path("userId") userId: Long,
        @Query("newPassword") newPassword: String? = null
    ): ApiResponse<Unit>
}

data class CreateUserRequest(
    val username: String,
    val password: String,
    val realName: String,
    val phone: String?,
    val roleType: Int,
    val regionId: Long?
)

data class UpdateUserRequest(
    val realName: String,
    val phone: String?,
    val roleType: Int,
    val regionId: Long?
)
